USE [Northwind]
GO

--Transact-SQL and sys.objects -> type in: U = Table, V = View, P = SQL Stored Procedure

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[EmployeeTerritories]') AND type in (N'U'))
DROP Table [dbo].[EmployeeTerritories]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Territories]') AND type in (N'U'))
DROP Table [dbo].[Territories]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Region]') AND type in (N'U'))
DROP Table [dbo].[Region]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[CustomerCustomerDemo]') AND type in (N'U'))
DROP Table [dbo].[CustomerCustomerDemo]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[CustomerDemographics]') AND type in (N'U'))
DROP Table [dbo].[CustomerDemographics]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Order Details]') AND type in (N'U'))
DROP Table [dbo].[Order Details]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Products]') AND type in (N'U'))
DROP Table [dbo].[Products]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Suppliers]') AND type in (N'U'))
DROP Table [dbo].[Suppliers]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Categories]') AND type in (N'U'))
DROP Table [dbo].[Categories]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Orders]') AND type in (N'U'))
DROP Table [dbo].[Orders]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Shippers]') AND type in (N'U'))
DROP Table [dbo].[Shippers]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Employees]') AND type in (N'U'))
DROP Table [dbo].[Employees]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Customers]') AND type in (N'U'))
DROP Table [dbo].[Customers]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Orders Qry]') AND type in (N'V'))
DROP VIEW [dbo].[Orders Qry]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Quarterly Orders]') AND type in (N'V'))
DROP VIEW [dbo].[Quarterly Orders]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Invoices]') AND type in (N'V'))
DROP VIEW [dbo].[Invoices]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Product Sales for 1997]') AND type in (N'V'))
DROP VIEW [dbo].[Product Sales for 1997]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Current Product List]') AND type in (N'V'))
DROP VIEW [dbo].[Current Product List]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Order Details Extended]') AND type in (N'V'))
DROP VIEW [dbo].[Order Details Extended]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Products Above Average Price]') AND type in (N'V'))
DROP VIEW [dbo].[Products Above Average Price]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Products by Category]') AND type in (N'V'))
DROP VIEW [dbo].[Products by Category]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Alphabetical list of products]') AND type in (N'V'))
DROP VIEW [dbo].[Alphabetical list of products]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Order Subtotals]') AND type in (N'V'))
DROP VIEW [dbo].[Order Subtotals]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Customer and Suppliers by City]') AND type in (N'V'))
DROP VIEW [dbo].[Customer and Suppliers by City]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Sales Totals by Amount]') AND type in (N'V'))
DROP VIEW [dbo].[Sales Totals by Amount]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Sales by Category]') AND type in (N'V'))
DROP VIEW [dbo].[Sales by Category]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Summary of Sales by Quarter]') AND type in (N'V'))
DROP VIEW [dbo].[Summary of Sales by Quarter]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Summary of Sales by Year]') AND type in (N'V'))
DROP VIEW [dbo].[Summary of Sales by Year]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Category Sales for 1997]') AND type in (N'V'))
DROP VIEW [dbo].[Category Sales for 1997]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[SalesByCategory]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[SalesByCategory] 
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[CustOrdersOrders]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[CustOrdersOrders] 
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[CustOrderHist]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[CustOrderHist] 
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[CustOrdersDetail]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[CustOrdersDetail]
GO 

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Ten Most Expensive Products]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[Ten Most Expensive Products]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Sales by Year]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[Sales by Year]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Employee Sales by Country]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[Employee Sales by Country] 
GO
